﻿using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Serilog;
using xjjxmm.infrastructure.Authorizations;
using XjjXmm.Infrastructure.Configuration;
using XjjXmm.Infrastructure.Constant;
using XjjXmm.Infrastructure.Jwt;

namespace xjjxmm.infrastructure.compont;

public class LogCompont
{
    public int Order { get; set; } = 10;

    public bool Regist(WebApplicationBuilder builder) {
        Log.Information($"EnvironmentName: {builder.Environment.EnvironmentName}");

        //扫描本地log及从配置中心读log
        builder.WebHost.ConfigureAppConfiguration((context, configurationBuilder) =>
        {
            configurationBuilder.Scan(builder.Environment.EnvironmentName);
            configurationBuilder.AddCustom();
        });

        //serilog
        ConfigHelper.Configuration = builder.Configuration;

        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(ConfigHelper.Configuration)
            .CreateBootstrapLogger();

        //Log.Information($"EnvironmentName2: {builder.Environment.EnvironmentName}");
        //Log.Information($"AppContext.BaseDirectory: {AppContext.BaseDirectory}");
        //Log.Information($"AppKit.GetCurrentDirectory: {AppKit.GetCurrentDirectory()}");
        //Log.Information($"Environment.CurrentDirectory: {Environment.CurrentDirectory}");

        //Console.WriteLine($"EnvironmentName2: {builder.Environment.EnvironmentName}");
        //Console.WriteLine($"AppContext.BaseDirectory: {AppContext.BaseDirectory}");
        //Console.WriteLine($"AppKit.GetCurrentDirectory: {AppKit.GetCurrentDirectory()}");
        //Console.WriteLine($"Environment.CurrentDirectory: {Environment.CurrentDirectory}");



        //builder.Host.UseSerilog();
        //注册级配置serilog
        builder.Host.UseSerilog((context, services, configuration) =>
        {
            configuration.ReadFrom.Configuration(ConfigHelper.Configuration);
        });

        Log.Information($"EnvironmentName3: {builder.Environment.EnvironmentName}");

        return true;
    }

   
}
